package com.demo.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.demo.dto.EasyUIGrid;
import com.demo.dto.EasyUIPage;
import com.demo.dto.Params;
import com.demo.entity.Post;
import com.demo.service.PostService;

@Controller
@RequestMapping(value = "/duty")
public class PostController {

	@Resource
	private PostService postService;
	
	@ResponseBody
	@RequestMapping(value = "/addPost", method = RequestMethod.POST)
	public int addPost(Post post) {
		return postService.insert(post);
	}
	
	@ResponseBody
	@RequestMapping(value = "/deletePost", method = RequestMethod.POST)
	public int deletePost(Post post) {
		return postService.delete(post);
	}
	
	@ResponseBody
	@RequestMapping(value = "/updatePost", method = RequestMethod.POST)
	public int updatePost(Post post) {
		return postService.updateByPrimaryKeySelective(post);
	}
	
	@RequestMapping(value = "/manage", method = RequestMethod.GET)
	public ModelAndView manage(ModelAndView modelAndView) {
		modelAndView.setViewName("post/manage");
		return modelAndView;
	}
	
	@ResponseBody
	@RequestMapping(value = "/findByParams", method = RequestMethod.GET)
	public EasyUIGrid findByParams(EasyUIPage page, Params params) {
		return postService.findByParams(page, params.getMap());
	}
	
}
